﻿using System;
using Coolite.Ext.Web;
using Pap.Web.Modules.Administration.ViewModel;
using Pap.Web.Utils;
using Utils.UIPermission;


namespace Pap.Web.Modules.Administration.Views
{
    /// <summary>
    /// 
    /// </summary>
    public partial class VillagesList : BasePage<VillagesListViewModel>, IPermittedPage
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                villageStore.DataSource = this.ViewModel.FindVillages("");
                villageStore.DataBind();
            }
        }

        /// <summary>
        /// Handles the Command event of the GrvVillages control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Coolite.Ext.Web.AjaxEventArgs"/> instance containing the event data.</param>
        protected void GrvVillages_Command(object sender, AjaxEventArgs e)
        {
            if (e.ExtraParams["CommandName"].Equals("Edit"))
            {
                RowSelectionModel model = grvVillages.SelectionModel.Primary as RowSelectionModel;
                Guid VillageID = new Guid(model.SelectedRows[0].RecordID);
                Ext.Redirect(string.Format("~/Administration/VillageDetails?VillageID={0}", VillageID), "Working....");
            }
        }


        #region IPermittedPage Members

        /// <summary>
        /// Gets the name of the permission.
        /// </summary>
        /// <value>
        /// The name of the permission.
        /// </value>
        public string PermissionName
        {
            get { return "VillageList"; }
        }

        #endregion
    }
}
